# coding:utf-8
# author:frank
# date:2025/1/3
import pygame
# 帧速率：指程序每秒在屏幕上绘制图像的数目
# 生成一个帧率对象
FPSClock = pygame.time.Clock()
pygame.init()

win_w=500
win_h=600
win = pygame.display.set_mode((win_w,win_h))
pygame.display.set_caption("动画应用")
win.fill('white')
pygame.display.flip()
r = 20
y = 50
x = win_w/2
pygame.draw.circle(win,'red',(x,y),r)
pygame.display.update()
i = 0
y_speed = 1
x_speed = 1
while True:
    FPSClock.tick(60)
    y+=2 * y_speed
    x+=1 * x_speed
    # 清理屏幕(重新刷白)
    win.fill('white')
    # 边界判断
    if y>=win_h-r or y<=r:
        y_speed *=-1
    if x>=win_w-r or x<=r:
        x_speed *=-1
    pygame.draw.circle(win, 'red', (x, y), r)
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()